﻿@model CodeStash.Models.Search.ShowSearchResultsViewModel
@using Telerik.Web.Mvc.UI
@using CodeStash.ExtensionsMethods
@{
    ViewBag.Title = "Create Search";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section SpecificPageHeadStuff
 {
    @Html.ScriptTag(Url.Content("~/Scripts/Controllers/Search/search.js"))
}
<div id="dialog-message" style="display: none;">
    <p id="dialog-message-content">
    </p>
</div>
<div id="SearchPanel">
    <h3>
        Search Results</h3>
    <p>
        Your search was</p>
    <ul>
        <li>Visibility : '@Model.Visibility.VisibilityDescription'</li>
        @switch (Model.SearchType)
        {
            case CodeStash.Common.Enums.SearchType.ByKeyWord:
            <li>Search Type : 'By Keyword', where your search term was : '@Model.SearchValue'</li>
                                                                     break;
            case CodeStash.Common.Enums.SearchType.ByLanguage:
            <li>Search Type : 'By Language', where your search language was : '@Model.Language.LanguageCode'</li>
                                                                          break;
            case CodeStash.Common.Enums.SearchType.ByTag:
            <li>Search Type : 'By Tag', where your search term was : '@Model.SearchValue'</li>
                                                                 break;
        }
    </ul>
    @foreach (var results in Model.CodeSnippets)
    {
        <div class="abbreviatedResult">
            <div class="results">
                <p class="popupButton">
                        <a href="#" class="popup-button" onclick="javascript:ShowSnippetPopup(@results.CodeSnippetId)">
                            Popup</a>
                    </p>
                <p class="showButton">
                    <a href="/CodeSnippet/DisplaySnippetsForAddAndEdit?codeSnippetId=@results.CodeSnippetId&wasAddOrEdit=false" class="show-button">
                        Show</a></p>
            </div>
            <div class="innerResult">
                <p class="Title">@results.Title</p>
                <p class="Description">@results.Description</p>
            </div>
        </div>
    }
    @if (Model.TotalCountOfSnippets > Model.CodeSnippets.Count)
    {
        //There's more data here, so we have to put a list into place.... 
    }
@*  <div id="searchResultsContainer">
        <div style="margin-top: 0px; height:240px">
    @(Html.Telerik().Grid<CodeStash.Common.DataAccess.EntityFramework.CodeSnippet>()
        .ScriptFilesPath("~/Scripts/Telerik")
        .HtmlAttributes(new { style = "margin:0px" })
        .Name("SearchResultsGrid")
            .DataBinding(dataBinding => dataBinding
                //Ajax binding
                .Ajax()
                //The action method which will return JSON
                .Select("_AjaxBinding", "Search")
            )
            .Columns(columns =>
            {

                //columns.Bound(o => o.CodeSnippetId).Title("Id").HeaderHtmlAttributes(new { @class = "id-column" }).ReadOnly(true);
                columns.Bound(o => o.Description).ReadOnly(true);
                columns.Bound(o => o.Title).ReadOnly(true);
                columns.Bound(o => o.CodeSnippetId).ClientTemplate("<a href=\"#\" class=\"popup-button\">View Details</a>")
                    .Title("Popup").Filterable(false).Sortable(false).Width(130).ReadOnly(true);
                columns.Bound(o => o.CodeSnippetId).ClientTemplate("<a href=\"#\" class=\"show-button\">View Details</a>")
                    .Title("Show").Filterable(false).Sortable(false).Width(130).ReadOnly(true);
            })
            .ClientEvents(e => e.OnRowDataBound("SearchResultsGrid_onRowDataBound"))
            .Pageable()
            .Scrollable(scroll => scroll.Height(200))
            .Filterable()
            .Sortable(sorting => sorting
            .SortMode(GridSortMode.SingleColumn)
                .OrderBy(o => o.Add(p => p.CodeSnippetId).Ascending()))

    )
    @*        </div>
    </div>*@
</div>
